/**
 * Created by Administrator on 2017\9\19 0019.
 */
import React from 'react';
import {Link} from 'react-router-dom';
import { Input,Menu,Dropdown,Icon } from 'antd';
import template from './../../commonui/template';
import  './../../css/User/UsrHeader.css';
import cookie from './../../commonui/cookie';
const Search = Input.Search;
const SubMenu = Menu.SubMenu;


class UsrHeader extends React.Component{
    constructor(props){
        super(props);
       this.drawLogin=this.drawLogin.bind(this);
        const user=cookie.get('user');
        this.state={
            user:user||this.props.info.user,
            lb:this.props.info.lb
        }
    }
    drawLogin(){
        if(this.state.user){
            return (<Link to={{pathname:"/UsrCenter",state:{user:this.state.user,lb:this.state.lb}}}>{this.state.user}</Link>)
        }else{
             return (<Link to={{pathname:"/login"}}>Login</Link>)
        }

    }
    render(){
        const menu=(
            <Menu>
                <Menu.Item>
                    <Link to={{pathname:"/Orgination",state:{user:this.state.user,lb:this.state.lb}}}>Orgination</Link>
                </Menu.Item>
                <Menu.Item>
                    <Link to={{pathname:"/PackageList",state:{user:this.state.user,lb:this.state.lb}}}>Package</Link>
                </Menu.Item>
            </Menu>
        )
        return (
            <div>
                 <header>
                    {/*<nav>
                        <li> <Link to={{pathname:"/UsrHome",state:{user:this.state.user,lb:this.state.lb}}}>Home</Link></li>
                        <li>
                            <Dropdown overlay={menu}>
                                <a className="ant-dropdown-link" hrf="#">Orgination&&Package<Icon type="down"/></a>
                            </Dropdown>
                        </li>
                        <li><Link to={{pathname:"/About",state:{user:this.state.user,lb:this.state.lb}}}>About</Link></li>
                       {this.drawLogin()}
                    </nav>*/}
                    <Menu mode="horizontal">
                        <Menu.Item>
                            <Link to={{pathname:"/UsrHome",state:{user:this.state.user,lb:this.state.lb}}}>Home</Link>
                        </Menu.Item>
                        <SubMenu title={<span><Icon type="setting" />Orgination&&Package</span>}>
                          {/*<MenuItemGroup title="Item 1">
                            <Menu.Item key="setting:1">Option 1</Menu.Item>
                            <Menu.Item key="setting:2">Option 2</Menu.Item>
                          </MenuItemGroup>*/}
                            <Menu.Item>
                                <Link to={{pathname:"/Orgination",state:{user:this.state.user,lb:this.state.lb}}}>Orgination</Link>
                            </Menu.Item>
                            <Menu.Item>
                               <Link to={{pathname:"/PackageList",state:{user:this.state.user,lb:this.state.lb}}}>Package</Link>
                            </Menu.Item>
                        </SubMenu>
                        <Menu.Item>
                            <Link to={{pathname:"/About",state:{user:this.state.user,lb:this.state.lb}}}>About</Link>
                        </Menu.Item>
                        <Menu.Item>
                             {this.drawLogin()}
                        </Menu.Item>
                    </Menu>
                    <div className="Search">
                        <img alt="Logo"/>
                        <span>Malaysia Medical Center</span>
                        <Search placeholder="input search text" style={{width:200}} onSearch={this.search}/>
                    </div>
                </header>
            </div>
        )
    }
}


export default template({
    id: 'UsrHeader',
    component: UsrHeader
});